class Solution:
    def maxFrequencyElements(self, nums: List[int]) -> int:
        ans = defaultdict(int)
        ret = max_n = 0
        for x in nums:
            ans[x] += 1
            c = ans[x]
            if c > max_n:
                ret = max_n = c 
            elif c == max_n:
                ret += c 
        return ret